// pages/syhui/syhui.js

const app = getApp();
Page({
  /**
   * 页面的初始数据
   */
  data: {
    quyuxin: '', //区域名
    openid: '',
    phone: '', //手机号
    CUSTOMER_TEL: '', //手机号
    sihuodong: '', //四个活动
    CON_VALUE: '', //判断活动显示
    SELECTED: '',
    HOT: '',
    wordKey: '',
    NEWTHEME: '',
    CON_CODE: '',
    jiami: '',
    session_key: '',
    MERCHANT: '',
  },

  shangjifen() {
    wx.navigateTo({  
      url: '../../pages/shangluojifenshangcheng/shangluojifenshangcheng',
    })
  },


  fenhsou () {
    wx.navigateTo({  
      url: '../../pages/yananqinshuangjie/yananqinshuangjie',
    })
  },

  viptiao() {
    wx.navigateTo({  
      url: '../../pages/xukexujingdiertiaoye/xukexujingdiertiaoye',
    })
  },

  youxinkia() {
    wx.navigateTo({  
      url: '../../pages/xukexujingtiaozhuan/xukexujingtiaozhuan',
    })
  },



  soushuo() {
    wx.navigateTo({  
      url: '../../pages/newshouyesousuo/newshouyesousuo',
    })
  },

  jiaguo() {
    wx.navigateTo({
      url: '../../pages/newqianyuantiaozhuan/newqianyuantiaozhuan',
    })
  },



  // 跳商城
  // qushangcheng() {
  //   wx.switchTab({
  //     url: '../../pages/sangcheng/sangcheng',
  //   })
  // },

  // 跳下面的权益
  ququnyi() {
    wx.navigateTo({


      url: '../../pages/tabticket/tabticket',
    })
  },





  // 跳转地区
  diqu() {
    wx.navigateTo({
      url: '../../pages/quyu/quyu',
    })
  },


  remenhuodong(e) {

    // const sb = e.currentTarget.dataset.item.CON_VALUE
    // console.log(sb);
    // console.log(`../../${sb}`, );
    // // this.data.CUSTOMER_TEL
    // wx.navigateTo({
    //   url: `../../${sb}?data=${this.data.CUSTOMER_TEL} `,
    // })

    console.log(e);
    if (e.currentTarget.dataset.item.VALID == 1) {
      console.log(e.currentTarget.dataset.item.CON_VALUE);
      const sb = e.currentTarget.dataset.item.CON_VALUE
      console.log(sb);
      console.log(`../../${sb}`, );
      // this.data.CUSTOMER_TEL
      wx.navigateTo({
        url: `../../${sb}?data=${this.data.CUSTOMER_TEL} `,
      })

    } else if (e.currentTarget.dataset.item.VALID == 2) {

console.log(e.currentTarget.dataset.item.CON_VALUE);
      const sb = e.currentTarget.dataset.item.CON_URL
      console.log(sb);
      console.log(`../../${sb}`, );
      wx.navigateTo({
        url: `../../${sb}?data=${e.currentTarget.dataset.item.CON_VALUE}`,
      })

    } else if (e.currentTarget.dataset.item.VALID == 3) {
      console.log(e.currentTarget.dataset.item.CON_VALUE);

      const sb = e.currentTarget.dataset.item.CON_VALUE
      wx.navigateToMiniProgram({
        shortLink: sb,
        //develop开发版；trial体验版；release正式版
        envVersion: 'release',
        success(res) {
          // 打开成功
          console.log("跳转小程序成功！", res);
        }
      })


    }else if (e.currentTarget.dataset.item.VALID == 4) {
      console.log(e.currentTarget.dataset.item.CON_VALUE);
      const sb = e.currentTarget.dataset.item.CON_VALUE
      console.log(sb);
      console.log(`../../${sb}`, );
      // this.data.CUSTOMER_TEL
      wx.switchTab({
        url: `../../${sb}?data=${this.data.CUSTOMER_TEL} `,
      })


    }
  },


  jinpinghuodong(e) {

    console.log(e.currentTarget);

    const sb = e.currentTarget.dataset.item.CON_VALUE
    console.log(sb);
    console.log(`../../${sb}`, );
    // this.data.CUSTOMER_TEL
    wx.navigateTo({
      url: `../../${sb}?data=${this.data.CUSTOMER_TEL} `,
    })
  },

















  tiaolian(e) {
    console.log(e);
    if (e.currentTarget.dataset.item.VALID == 1) {
      console.log(e.currentTarget.dataset.item.CON_VALUE);
      const sb = e.currentTarget.dataset.item.CON_VALUE
      console.log(sb);
      console.log(`../../${sb}`, );
      // this.data.CUSTOMER_TEL
      wx.navigateTo({
        url: `../../${sb}?data=${this.data.CUSTOMER_TEL} `,
      })

    } else if (e.currentTarget.dataset.item.VALID == 2) {


      const sb = e.currentTarget.dataset.item.CON_VALUE
      console.log(sb);
      console.log(`../../${sb}`, );
      wx.navigateTo({
        url: `../../${sb}?data=${e.currentTarget.dataset.item.CON_URL} `,
      })

    } else if (e.currentTarget.dataset.item.VALID == 3) {
      console.log(e.currentTarget.dataset.item.CON_VALUE);

      const sb = e.currentTarget.dataset.item.CON_VALUE
      wx.navigateToMiniProgram({
        shortLink: sb,
        //develop开发版；trial体验版；release正式版
        envVersion: 'release',
        success(res) {
          // 打开成功
          console.log("跳转小程序成功！", res);
        }
      })
    }


    
  },


  collections() {


    this.setData({

      jiami: app.globalData.jiami,
      openid: app.globalData.openid,
      OPEN_ID: app.globalData.openid,
      session_key: app.globalData.session_key,

    })






    wx.request({
      url: app.globalData.interface+'/newVersion/API_2030_NewIndexData',
      method: 'POST',
      data: {

        OPEN_ID: this.data.OPEN_ID, //用户OPEN_ID
        session_key: this.data.session_key,
        OPEN_UUID: this.data.jiami,
      },
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },

      success: res => {
        console.log(res);
        this.setData({
          sihuodong: res.data.NEWTOP, //四个活动
          NEWTHEME: res.data.NEWTHEME, //全省六个活动

        })

      }
    })
  },


















  //页面模块
  yemianmokuai() {
    this.setData({

      CON_CODE: app.globalData.chenshiID,
    });

    console.log(this.data.CON_CODE);

    wx.request({
      url: app.globalData.interface+'/newVersion/API_2035_NEWALLDEMOData',
      method: 'POST',
      data: {
        CON_CODE: this.data.CON_CODE, //用户OPEN_ID
      },
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },

      success: res => {
        console.log(res);
        console.log(res.data.HOT);

        this.setData({
          sihuodong: res.data.NEWTOP, //四个活动
          NEWTHEME: res.data.NEWTHEME, //全省六个活动
          HOT: res.data.HOT,
          SELECTED: res.data.SELECTED,
          MERCHANT: res.data.MERCHANT,
        })
      }
    })
  },







  zhuce() {

    this.setData({

      jiami: app.globalData.jiami,
      OPEN_ID: app.globalData.openid,
      openid: app.globalData.openid,
      session_key: app.globalData.session_key,

    })



    wx.request({
      url: app.globalData.interface+'/xianPost/API_6403_SelectXianUserIntegral',
      method: 'POST',
      data: {
        OPEN_ID: this.data.OPEN_ID, //用户OPEN_ID
        session_key: this.data.session_key,
        OPEN_UUID: this.data.jiami,

      },
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      success: res => {

        if (res.data.code == '0') {
          wx.navigateTo({
            url: '../../pages/newquanyizhuce/newquanyizhuce',
          })
        } else if (res.data.code == '1') {
          wx.showModal({
            title: '温馨提示',
            content: '请联系客户经理添加权益',
            success: function (res) {
              if (res.confirm) { //这里是点击了确定以后
       
              } else { //这里是点击了取消以后
                console.log('用户点击取消')
              }
            }
          })
        } else if (res.data.code == '2') {

          console.log(res.data.data.INTEGRAL);
          wx.navigateTo({
            url: '../../pages/xianyonghuquanyispliebiao/xianyonghuquanyispliebiao?data=' + JSON.stringify(res.data.data.INTEGRAL)
          })
        }
      }
    })


  },


  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(e) {

    console.log(e);

 
      this.setData({
        phone: app.globalData.phone,
        jiami: app.globalData.jiami,
        OPEN_ID: app.globalData.openid,
        openid: app.globalData.openid,
        session_key: app.globalData.session_key,
        quyuxin: app.globalData.quyuxin,

      })
 



  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

    this.setData({
      quyuxin: app.globalData.quyuxin,

    });

    setTimeout(() => {
      // this.collections()
      this.yemianmokuai()
    }, 1000)



  },





  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})